<?php
namespace app\admin\controller;
use app\common\model\Config;
use app\common\model\ManagerGongzi;
use app\common\model\ManagerGongziKouchu as ManagerGongziKouchuModel;
use app\common\model\ManagerStudent as ManagerStudentModel;

class Managergongzikouchu extends Base
{
    public function __construct () {
        parent::__construct();
    }
    /*
     列表
     */
    public function list(){
        $input = input('get.');
        $where = [
            'mgid' => $input['mgid']
        ];
        $kouchulist = ManagerGongziKouchuModel::getAll($where);
        if(!$kouchulist) {
            return returnJson(0,'',[]);
        }
        return returnJson(0,'',$kouchulist);
    }

    public function update()
    {
        if(request()->isPost()){
            //工资信息
            $where = array(
                'id' => input('id')
            );
            ManagerGongziModel::gongziUpdate($where);
            return returnJson(1,'更新成功');
        }
        return returnJson(0,'更新失败');

    }

    // 添加招新学员
    public function add()
    {
        if(request()->isPost()){
            $input  = input('post.');
            $where = array();
            // 学员信息是否存在
            if ($input['mgid']){
                // 获取工资信息
                $g_where['id'] = $input['mgid'];
                $gongzi = ManagerGongzi::getColumn($g_where,'id');
                // 工资信息是否存在
                if(!$gongzi){
                    return returnJson(1,'工资信息不存在');
                }else{

                        // 添加记录
                        $time = time();
                        $save = array(
                            'mgid' => $input['mgid'],
                            'content' => $input['content'],
                            'money' => $input['money'],
                            'time' => $input['time'],
                            'mid' => $this->manager['id'],
                            'update_time' => $time,
                            'create_time' => $time
                        );
                    ManagerGongziKouchuModel::setInsertGetId($save);
                        // 更新工资
                        $where['id']=$input['id'];
                        $config = Config::getColumn(array(),'name,value');
                        ManagerGongzi::setFieldInc($where,'zhaoxin',$config['zhaoxin_gongzi']);
                        return returnJson(0,'添加成功');

                }
            }else{
                return returnJson(1,'请填写学员ID');
            }
        }

        return returnJson(1,'添加失败');
    }
//删除
    public function del()
    {
        if(request()->isPost()){
            $input = input('post.');
            $where = array(
                'id' => $input['id']
            );
            ManagerGongziKouchuModel::setDel($where);

            return returnJson(0,'删除成功');
        }
        return returnJson(1,'删除失败');
    }

}
